﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteLib.Data;
using SiteLib.Tools;

namespace SiteLib
{
    public partial class Info : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
                {
                    string sId = Request.QueryString["Id"];
                    int iId;
                    if (int.TryParse(sId, out iId))
                    {
                        List<SiteMenuItem> sm = SiteMenuItem.GetMenuItemsByKeyId(iId, (int)EnumHelper.PageType.InformationBlock);
                        if (sm != null)
                        {
                            rptSubMenu.DataSource = sm.OrderBy(i => i.Title);
                            rptSubMenu.DataBind();
                        }

                        SiteContent targetSiteContent = SiteContent.Get(iId);
                        if (targetSiteContent != null)
                        {
                            lMainContent.Text = targetSiteContent.Content;
                            lMainContentTitle.Text = targetSiteContent.Title;

                            rptFiles.DataSource = targetSiteContent.FileAttachements;
                            rptFiles.DataBind();
                        }
                    }
                }
            }
        }
    }
}